﻿using supermarket.method;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace supermarket
{
    public partial class supnewuser : Form
    {
        public supnewuser()
        {
            InitializeComponent();
        }

        //清空
        private void button3_Click(object sender, EventArgs e)
        {
            textuser.Text = "";
            textnumber.Text = "";
        }

        //返回
        private void button2_Click(object sender, EventArgs e)
        {
    
           
        }

        //添加
        private void button1_Click(object sender, EventArgs e)
        {

            //判断手机号
            string number = this.textnumber.Text;
            if (!CommonHelper.IsValidPhoneNumber(number))
            {
                MessageBox.Show("请输入正确的手机号");
                return;
            }


            Classuser us = new Classuser();
            if (us.userselect(textnumber.Text, "") == true)   //判断用户名是否存在
            {
                MessageBox.Show("手机号已存在！", "", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
            }
            else
            {
                if (us.usernew(textuser.Text, textnumber.Text) == 1)
                {
                    MessageBox.Show("新建用户成功！", "", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("新建用户失败！", "", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                }
            }
        }
    }
}
